package edu.zut.servlet;

import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;

/**
 * servlet：单实例模式   web容器（tomcat）决定的
 * 意味不管几个用户发起pv请求，大家所访问的对象是一个
 */
@WebServlet(name = "pvServlet", urlPatterns = "/pv")
public class PVServlet extends HttpServlet {

    //将count视作访问pv资源的计数器
    int count = 0;

    //做一个统计，统计/pv发生了多次请求
    @Override
    protected void doGet(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
        count++;
        resp.setContentType("text/html;charset=utf-8");
        resp.getWriter().write("访问pv的次数：" + count);
    }
}
